/**
 * Created With IntelliJ IDEA
 * Description:leetcode：27. 移除元素
 * <a href="https://leetcode.cn/problems/remove-element/">...</a>
 * User: DELL
 * Data: 2022-12-02
 * Time: 20:06
 */


public class Solution {
    public int removeElement(int[] nums, int val) {
        //判空处理
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int index = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val) {
                nums[index++] = nums[i];
            }
        }
        return index;
    }
}